package com.cn.wanxi.service;

import com.cn.wanxi.dao.ProductDao;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.util.IO;
import com.cn.wanxi.util.PAHT;
import com.cn.wanxi.util.Tool;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 产品控制层
 */
public class ProductService {
    private String split = PAHT.SPLIT.getPath();

    /**
     * 得到页面下放滚动产品
     * @return
     */
    public ArrayList<ProductModel> getCarouselProductModelListForAboutUs() {
        List<String> CarouselProductImgList = new ArrayList();
        List<String> CarouselProductTextList = new ArrayList();

        ProductDao productDao = new ProductDao();
        int length = productDao.getAboutImgsList().size();
        for (int i = 0; i <length; i++) {
            CarouselProductImgList.add(productDao.getAboutImgsList().get(i));
            CarouselProductTextList.add(productDao.getAboutTextsList().get(i));
        }
        String CarouselProductImg = Tool.replaceText(CarouselProductImgList.toString());
        String CarouselProductTextist = Tool.replaceText(CarouselProductTextList.toString());
        String addStr = CarouselProductImg+split+CarouselProductTextist;
        //写
        IO.writeNotepad(addStr, PAHT.PRODUCTSERVICE_FILE_NAME.getPath());
        //读
        String[] str = IO.readNotepad().split(split);//aaaaaa@@@@bbbbbbb
        List<String> List=new ArrayList(Arrays.asList(str));//集合1{a,a,a,a,a,a,a}和集合2{b,b,b,b,b,b,b,b}
        ArrayList<ProductModel> productModelList = new ArrayList<>();
        for (int i = 0; i <length; i++) {
            ProductModel productModel = new ProductModel();
            productModel.setAboutImg(List.get(0).split(",")[i]);
            productModel.setAboutText(List.get(1).split(",")[i]);
            productModelList.add(productModel);
        }
        return productModelList;
    }
    /**
     * 得到课程中心的产品课程
     * @return
     */
    public ArrayList<ProductModel> getProductModelListForProduct() {
        List<String> croductImgList = new ArrayList();
        List<String> croductNameList = new ArrayList();
        List<String> courseCenterMarketPricesgList = new ArrayList();
        List<String> courseCenterPricesList = new ArrayList();
        ProductDao productDao = new ProductDao();
        int length = productDao.getCourseCenterImgsList().size();
        for (int i = 0; i <length; i++) {
            croductImgList.add(productDao.getCourseCenterImgsList().get(i));
            croductNameList.add(productDao.getCourseCenterProductNamesList().get(i));
            courseCenterMarketPricesgList.add(productDao.getCourseCenterMarketPricesList().get(i));
            courseCenterPricesList.add(productDao.getCourseCenterPricesList().get(i));
        }
        String croductImg = Tool.replaceText(croductImgList.toString());
        String croductName = Tool.replaceText(croductNameList.toString());
        String courseCenterMarketPricesg = Tool.replaceText(courseCenterMarketPricesgList.toString());
        String courseCenterPrices = Tool.replaceText(courseCenterPricesList.toString());

        String addStr = croductImg+split+croductName+split+courseCenterMarketPricesg+split+courseCenterPrices;
        //写
        IO.writeNotepad(addStr, PAHT.PRODUCTSERVICE_FILE_NAME.getPath());
        //读
        String[] str = IO.readNotepad().split(split);//aaaaaa@@@@bbbbbbb
        List<String> List=new ArrayList(Arrays.asList(str));//集合1{a,a,a,a,a,a,a}和集合2{b,b,b,b,b,b,b,b}
        ArrayList<ProductModel> productModelList = new ArrayList<>();
        for (int i = 0; i <length; i++) {
            ProductModel productModel = new ProductModel();
//            productModel.setAboutText("wa");
//            productModel.setAboutImg("wa");
            productModel.setProductImg(List.get(0).split(",")[i]);
            productModel.setProductName(List.get(1).split(",")[i]);
            productModel.setCourseCenterMarketPrices(List.get(2).split(",")[i]);
            productModel.setCourseCenterPrices(List.get(3).split(",")[i]);
            productModelList.add(productModel);
        }
        return productModelList;
    }
}
